//公共
import myHeader from "/pages/headerfoot/pages/header.vue"
//表格
import uniForms from "/uni_modules/uni-forms/components/uni-forms/uni-forms.vue";
//语言
import Lang from '@/utils/lang.js';
//公共公益方法
import commonBenefit from '@/common/commonbenefit.js';
//公共方法
import Base from '@/common/base.js';
//表格
import uDataSelect from "/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue";
//微信api
import weChat from '@/lib/wechat.js';
//登录api
import Login from '@/lib/login.js';
//用户
import User from '@/lib/user.js';
//公共底部
import Tabbar from "/pages/headerfoot/pages/benefitfooter.vue";
// 图标1
import uniIcons from "/uni_modules/uni-icons/components/uni-icons/uni-icons.vue";

export default {
	components: {
		uniIcons,
		myHeader,
		uniForms,
		uDataSelect,
		Tabbar
	},
	data() {
		return {
			informationfilling: Lang.lang.reviewapplication,
			user_mobile: '',
			valiFormData: {
				user_id: '',
			},
			string: '', //当前
			stringname: '',
			show: false,
			selectedarr:[], //选择用户
			selectednamearr: [], //选择名称
			selectedvalue: '', //选择
			ifclick:true,//是否点击
			ifdata:false,//是否有数据
			//校验规则
			rules: {
				user_id: {
					rules: [{
						required: true,
						errorMessage: '用户不为空'
					}]
				}
			}
		}
	},
 
	onShow() {
		var that = this;
		that.ifreglogin();
	},
	methods: {
		//判断是否需要注册或者登录与其他
		async ifreglogin() {
			var that = this;
			//注册
			await Base.globalauthorization();
		},
		//搜索
		iconClick() {
			var that = this;
			that.show = false;
			that.ifclick= true;
			that.ifdata= false;//是否有数据
			//重新赋值
			that.stringname = '';
			that.string = '';
			var data = {};
			//获取用户
			data['user_mobile'] = that.user_mobile;
			commonBenefit.getUserApiMethod(data).then(res => {
				that.show = true;
				if (res) {
					//判断是否
					if (res.user_mobile) {
						that.string = res
						that.stringname = res.username + '-' + res.user_mobile
						that.selectedvalue= res.user_id;
						that.ifdata=true;//是否有数据
					}else{
						that.stringname = Lang.lang.nodata
					}
				}
			});
		},
		 
		//提交
		submitok: function(e) {
			var that = this;
			that.ifclick= false;
			if (that.selectedvalue) {
				that.selectedarr.push({id:that.selectedvalue}); //选择用户
				that.selectednamearr.push(that.stringname); //选择名称
			}
		},
		//删除
		del(e) {
			var that = this;
			var selectednamearr = that.selectednamearr;
			var selectedarr = that.selectedarr;
			that.selectednamearr.splice(e, 1);
			that.selectedarr.splice(e, 1);
		},
		//提交
		submit() {
			var that=this;
			var data={};
			data['user_id']=JSON.stringify(that.selectedarr);
			commonBenefit.addUserManageApiMethod(data).then(res => {
				 if(res){
					 Base.publicshowtoastsuccess(res.msg,commonBenefit.automaticurl('reviewapplication'))
				 }
			}); 
		},
	}
}